home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 4404 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: cs.ruu.nl!usenet
  2. From: wsldanke@cs.ruu.nl (Wessel Dankers)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: x ^= y ^= x ^= y;
  5. Date: 28 Feb 96 20:13:44 +0100
  6. Organization: Dept of Computer Science, Utrecht University, The Netherlands
  7. Message-ID: <2141.6632T1213T2220@cs.ruu.nl>
  8. References: <1286.6624T1439T237@cs.ruu.nl> <4gij61$81i@news.ox.ac.uk>
  9.     <3131C523.1ECC@sapiens.com> <4h075l$2go@elmer.tsc.com>
  10. NNTP-Posting-Host: anx1p14.cc.ruu.nl
  11. X-Newsreader: THOR 2.22 (Amiga TCP/IP)
  12.  
  13. Bill Roberts <billr@elmer.tsc.com> wrote:
  14. > In article <3131C523.1ECC@sapiens.com>, Avi Lev  <avil@sapiens.com> wrote:
  15. >>Benjamin Hutchings wrote:
  16. >>it'll damn right WILL work because this is proper C syntax and
  17. >>therefore must work, if it doesn't then your compiler had better
  18. >>be replaced for a real C compiler cuz it obviously isn't one.
  19. Damn right! Tell'm, Ben!
  20.  
  21. > What expression result will be in x at the end of the expression?  The
  22. > first one or the second one?  The compiler may choose either.  The c
  23. No it definitely CAN'T choose!
  24. The return value of an assignment is strictly documented and an ANSI feature!
  25.  
  26. > standard specifically says that the results of this statement are
  27. > undefined.  Consider the following:
  28. >    x = 1;
  29. >    y = 2;
  30. >    x = y += x += y;
  31. (x += y) will have the value of the new x, so that'll be 3
  32. y += (3) will have the value of the new y, being 5
  33. x = (5) will therefore assign the value 5 to x.
  34.  
  35. > Will x contain 3 or 5.  It depends on what order the compiler stores
  36. x and y will both contain 5.
  37.  
  38. > the results of the expressions in the statement.  This is the same
  39. The order is predefined: an assignment statement is of course right-
  40. associative:
  41. (x = y) = 4
  42. has no meaning: how can you assign a value to a statement? A statement is no
  43. lvalue.
  44. x = (y = 4)
  45. however, _is_ sensible.
  46.  
  47. > problem you will have with
  48. >    i = 1;
  49. >    x[ i++ ] = y[ i++ ];
  50. > What will be the value of i at the end?  And which value will be used
  51. i++ means: increase i with one after using it. In this expression i is
  52. increased twice in each pass.
  53. while(d++ = s++);
  54. for two arrays d[] and s[] (for each type) is valid, though.
  55.  
  56. > for which array?  It is up to the compiler, and specifically declared
  57. > to be undefined in the c standard.
  58.  
  59.  
  60.  
  61. --
  62. Wessel Dankers                 _\\|//_            <wsldanke@cs.ruu.nl>
  63.                                ///|\\\
  64. ----------------------------oOO--(_)---OOo----------------------------
  65. `Never imagine yourself not to be otherwise than what it might appear
  66. to others that what you were or might have been was not otherwise than
  67. what you had been would have appeared to them to be otherwise.'
  68.  
  69.